/**
 * 算式测试类 - 实验内容1
 * 对算式类进行单元测试
 */
public class ExpressionTest {
    public static void main(String[] args) {
        System.out.println("实验内容1 - 算式类和习题类测试");
        System.out.println("===============================");
        
        // 测试算式类
        testExpressionClass();
        
        // 测试习题类
        testExerciseClass();
        
        System.out.println("===============================");
        System.out.println("实验内容1测试完成");
    }
    
    public static void testExpressionClass() {
        System.out.println("\n1. 算式类单元测试");
        
        // 创建测试用例
        Expression addExpr = new Expression(15, 8, "+");
        Expression subExpr = new Expression(20, 7, "-");
        Expression subSwap = new Expression(5, 12, "-");
        
        // 测试加法功能
        System.out.println("测试加法: " + addExpr.toString());
        if (addExpr.calculate() != 23) {
            System.out.println("错误: 15+8应该等于23");
            return;
        }
        if (!addExpr.checkAnswer(23)) {
            System.out.println("错误: 答案23应该正确");
            return;
        }
        
        // 测试减法功能
        System.out.println("测试减法: " + subExpr.toString());
        if (subExpr.calculate() != 13) {
            System.out.println("错误: 20-7应该等于13");
            return;
        }
        
        // 测试自动交换
        System.out.println("测试自动交换: " + subSwap.toString());
        if (subSwap.calculate() != 7) {
            System.out.println("错误: 5-12应自动交换为12-5=7");
            return;
        }
        
        System.out.println("算式类单元测试通过");
    }
    
    public static void testExerciseClass() {
        System.out.println("\n2. 习题类单元测试");
        
        Exercise exercise = new Exercise();
        
        // 测试手动添加
        exercise.addExpression(new Expression(10, 5, "+"));
        exercise.addExpression(new Expression(20, 8, "-"));
        System.out.println("手动添加测试:");
        exercise.displayQuestions();
        
        // 测试自动生成
        Exercise autoExercise = new Exercise();
        autoExercise.generateExercises(5);
        System.out.println("自动生成5道题:");
        autoExercise.displayQuestions();
        autoExercise.displayAnswers();
        
        // 验证统计信息
        System.out.println("统计信息: " + autoExercise.getStatistics());
        if (autoExercise.getSize() != 5) {
            System.out.println("错误: 应该生成5道题");
            return;
        }
        
        System.out.println("习题类单元测试通过");
    }
}